﻿using IntelligentAgriculture.Contracts.Dto.Input;
using IntelligentAgriculture.Contracts.Dto.Input.EarTagInput;
using IntelligentAgriculture.Contracts.Dto.Output;
using IntelligentAgriculture.Contracts.Interface;
using IntelligentAgriculture.Domain.Enum;
using IntelligentAgriculture.WebAPI.Application.Command.BreedingWeighCommand;
using IntelligentAgriculture.WebAPI.Application.Command.DepartMentCommand;
using IntelligentAgriculture.WebAPI.Application.Command.SheepCommand;
using IntelligentAgriculture.WebAPI.Application.CommandHandler.BreedingWeighCommandHandler;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace IntelligentAgriculture.WebAPI.Controllers
{
    /// <summary>
    /// 羊只称重
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BreedingWeighController : ControllerBase
    {

        private readonly IBreedingWeighService breedingService;
        private readonly TokenService tokenService;
        private readonly ILogger<BreedingWeighController> logger;
        private readonly IMediator mediator;

        /// <summary>
        /// 注入
        /// </summary>
        /// <param name="breedingService"></param>
        /// <param name="tokenService"></param>
        /// <param name="logger"></param>
        /// <param name="mediator"></param>
        public BreedingWeighController(IBreedingWeighService breedingService
            , TokenService tokenService
            , ILogger<BreedingWeighController> logger, IMediator mediator)
        {
            this.breedingService = breedingService;
            this.tokenService = tokenService;
            this.logger = logger;
            this.mediator = mediator;

        }


        /// <summary>
        /// 羊只称重列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        /// 
        [HttpPost]
        public async Task<Results<PageOutput<BreedingWeighOutPut>>> BreedingWeighList(BreedingWeighInPut input)
        {

            var command = new BreedingWeighQueryCommand(input);
            var roles = await mediator.Send(command);
            return roles;

        }




        /// <summary>
        /// 枚举列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
         public object WeighCategoryList()
        {
            List<object> list = new List<object>();
            foreach (WeighCategoryEnum item in Enum.GetValues(typeof(WeighCategoryEnum)))
            {
                list.Add(new
                {
                    name = item.ToString(),
                    Value = item
                });
            }
            return Results<object>.DataResult(list);
        }




        /// <summary>
        /// 删除称重信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<int>> DeleteWeighCategory(BreedingWeighDeleteCommand command)
        {
            return await mediator.Send(command);
        }



        /// <summary>
        /// 添加称重信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<int>> AddWeighCategory(BreedingWeighCreateCommand command)
        {
            return await mediator.Send(command);
        }

        /// <summary>
        /// 修改称重信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        /// 
        [HttpPost]
        public async Task<Results<int>> UpdateWeighCategory(BreedingWeighUpdateCommand command)
        {
            return await mediator.Send(command);
        }






    }





}
